package com.project.servic.impl;

import com.project.bean.CutPageBean;
import com.project.bean.PostBean;
import com.project.dao.IReplyDao;
import com.project.dao.PostDao;
import com.project.servic.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class PostServiceImpl implements IPostService {
    @Autowired
    private PostDao dao;
    @Autowired
    private IReplyDao daos;
    @Override
    public CutPageBean<PostBean> findChannelById(Integer channelId, Integer pageNo, String userName, String postName, LocalDate startDate, LocalDate endDate) {
        return dao.findChannelById(channelId,  pageNo, userName, postName,  startDate, endDate);
    }

    @Override
    public List<PostBean> add(PostBean post) {
        dao.add(post);
        return dao.findByPostId(post.getChannel().getId());
    }

    @Override
    public PostBean findById(Integer id) {
        PostBean post = dao.findById(id);
        post.setReplyList(daos.findById(id));
        return post;
    }
}
